package com.futurelight.recipes.ui.fragment;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import android.util.Base64;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;

import com.futurelight.recipes.R;
import com.futurelight.recipes.model.Result;

import java.nio.charset.StandardCharsets;


public class DetailFragment extends Fragment {

    private final Result result;
    private View rootView;

    public DetailFragment(Result result) {
        this.result = result;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        rootView = inflater.inflate(R.layout.fragment_detail, container, false);
        return rootView;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        WebView summary = rootView.findViewById(R.id.summary);
        String html = "<style>b {color: #ffff00;font-style:italic;}body {font-size: 20px;color: #ffffff;}</style>" + result.summary;
        String s = Base64.encodeToString(html.getBytes(StandardCharsets.UTF_8), Base64.NO_PADDING);

        summary.loadData(s, "text/html", "base64");
        summary.setBackgroundColor(0);
        summary.getBackground().setAlpha(0);

    }
}